<p>This rule raises an issue when <code>String.match()</code> or <code>RegExp.exec()</code> methods are used in boolean contexts where only the
existence of a match matters, not the actual match details.</p>
<h2>Why is this an issue?</h2>
<p>When you only need to check if a regular expression pattern exists in a string, using <code>String.match()</code> or <code>RegExp.exec()</code> is
inefficient. These methods create and return match objects or arrays containing detailed information about the matches, which requires additional
memory allocation and processing time.</p>
<p>The <code>RegExp.test()</code> method is specifically designed for boolean checks. It returns <code>true</code> if the pattern is found and
<code>false</code> otherwise, without creating any match objects. This makes it faster and more memory-efficient for simple existence checks.</p>
<p>Using the wrong method can impact performance, especially in loops or frequently executed code paths. It also makes the code less clear about its
intent - when you see <code>test()</code>, it’s immediately obvious that only a boolean result is needed.</p>
<h3>What is the potential impact?</h3>
<p>Using <code>String.match()</code> or <code>RegExp.exec()</code> instead of <code>RegExp.test()</code> for boolean checks creates unnecessary
performance overhead through extra memory allocation and processing. In performance-critical code or loops, this can lead to measurable slowdowns and
increased memory usage.</p>
<h3>How to fix?</h3>
<p>Replace <code>String.match()</code> calls with <code>RegExp.test()</code> when used in boolean contexts. Move the regular expression to the left
side and call <code>test()</code> with the string as an argument.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
if (string.match(/unicorn/)) {
  // do something
} // Noncompliant
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
if (/unicorn/.test(string)) {
  // do something
}
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-regexp-test.md">prefer-regexp-test</a> </li>
  <li> MDN: RegExp.prototype.test() - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test">Official
  documentation for the RegExp test() method</a> </li>
  <li> MDN: String.prototype.match() - <a
  href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match">Official documentation for the String match()
  method</a> </li>
  <li> MDN: RegExp.prototype.exec() - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec">Official
  documentation for the RegExp exec() method</a> </li>
</ul>
